package com.getpebble.android.framework.protocol.outbound;

import com.getpebble.android.R;
import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.framework.util.ByteUtils;
import com.getpebble.android.framework.util.PebbleCapabilities.ConnectedDevice;
import com.sun.mail.imap.protocol.ListInfo;
import com.sun.mail.smtp.SMTPMessage;
import java.util.UUID;

public class PblOutboundAppInstallMessage extends PblOutboundMessage {
    private UUID mAppUuid;
    private int mBankNumber;
    private AppInstallCommand mCommand;
    private int mInstallId;
    private boolean mShouldVibrate;

    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand = new int[AppInstallCommand.values().length];

        static {
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[AppInstallCommand.GET_BANK_INFO.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[AppInstallCommand.GET_UUID_LIST.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[AppInstallCommand.GET_CURRENT_APP_UUID.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[AppInstallCommand.UUID_APP_INFO.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[AppInstallCommand.APP_AVAILABLE.ordinal()] = 5;
            } catch (NoSuchFieldError e5) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[AppInstallCommand.REMOVE_APP.ordinal()] = 6;
            } catch (NoSuchFieldError e6) {
            }
            try {
                $SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[AppInstallCommand.UPGRADE_APP.ordinal()] = 7;
            } catch (NoSuchFieldError e7) {
            }
        }
    }

    public enum AppInstallCommand {
        GET_BANK_INFO((byte) 1),
        REMOVE_APP((byte) 2),
        APP_AVAILABLE((byte) 3),
        GET_UUID_LIST((byte) 5),
        UUID_APP_INFO((byte) 6),
        GET_CURRENT_APP_UUID((byte) 7),
        UPGRADE_APP((byte) 8);
        
        private final byte mCode;

        private AppInstallCommand(byte code) {
            this.mCode = code;
        }

        public byte getCode() {
            return this.mCode;
        }
    }

    private PblOutboundAppInstallMessage(AppInstallCommand command) {
        super(EndpointId.APP_INSTALL_MANAGER);
        this.mCommand = command;
    }

    private void setBankNumber(int bankNumber) {
        this.mBankNumber = bankNumber;
    }

    private void setAppUuid(UUID appUuid) {
        this.mAppUuid = appUuid;
    }

    private void setShouldVibrate(boolean shouldVibrate) {
        this.mShouldVibrate = shouldVibrate;
    }

    public static PblOutboundAppInstallMessage createGetBankInfo() {
        return new PblOutboundAppInstallMessage(AppInstallCommand.GET_BANK_INFO);
    }

    public static PblOutboundAppInstallMessage createRemoveApp(UUID uuid) {
        PblOutboundAppInstallMessage message = new PblOutboundAppInstallMessage(AppInstallCommand.REMOVE_APP);
        message.setAppUuid(uuid);
        return message;
    }

    public static PblOutboundAppInstallMessage createAppAvailable(int bankNumber, boolean shouldVibrate) {
        PblOutboundAppInstallMessage message = new PblOutboundAppInstallMessage(AppInstallCommand.APP_AVAILABLE);
        message.setBankNumber(bankNumber);
        message.setShouldVibrate(shouldVibrate);
        return message;
    }

    public static PblOutboundAppInstallMessage createGetList() {
        return new PblOutboundAppInstallMessage(AppInstallCommand.GET_UUID_LIST);
    }

    public static PblOutboundAppInstallMessage createGetAppInfo(UUID appUuid) {
        PblOutboundAppInstallMessage message = new PblOutboundAppInstallMessage(AppInstallCommand.UUID_APP_INFO);
        message.setAppUuid(appUuid);
        return message;
    }

    public static PblOutboundAppInstallMessage createUpgradeApp(UUID appUuid) {
        PblOutboundAppInstallMessage message = new PblOutboundAppInstallMessage(AppInstallCommand.UPGRADE_APP);
        message.setAppUuid(appUuid);
        return message;
    }

    private void addBytesSimple() {
        addBytes(Byte.valueOf(this.mCommand.getCode()));
    }

    private void addBytesUUID() {
        addBytes(Byte.valueOf(this.mCommand.getCode()));
        addBytes(ByteUtils.uuid2bytes(this.mAppUuid));
    }

    private void addByteShouldVibrate() {
        int i;
        if (this.mShouldVibrate) {
            i = 1;
        } else {
            i = 0;
        }
        byte shouldVibrate = (byte) i;
        addBytes(Byte.valueOf(shouldVibrate));
    }

    private void addBytesInstallAndBank() {
        addBytes(Byte.valueOf(this.mCommand.getCode()));
        addBytes(ByteUtils.int2bytes(this.mInstallId));
        addBytes(ByteUtils.int2bytes(this.mBankNumber));
    }

    private void addBytesBank() {
        addBytes(Byte.valueOf(this.mCommand.getCode()));
        addBytes(ByteUtils.int2bytes(this.mBankNumber));
    }

    public synchronized byte[] getBytes() {
        if (!areBytesCached()) {
            switch (AnonymousClass1.$SwitchMap$com$getpebble$android$framework$protocol$outbound$PblOutboundAppInstallMessage$AppInstallCommand[this.mCommand.ordinal()]) {
                case SMTPMessage.RETURN_FULL /*1*/:
                case SMTPMessage.RETURN_HDRS /*2*/:
                case ListInfo.INDETERMINATE /*3*/:
                    addBytesSimple();
                    break;
                case SMTPMessage.NOTIFY_DELAY /*4*/:
                    addBytesUUID();
                    break;
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsHeaderTextAppearance /*5*/:
                    addBytesBank();
                    if (ConnectedDevice.isVibrateSupported()) {
                        addByteShouldVibrate();
                        break;
                    }
                    break;
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsBackground /*6*/:
                case R.styleable.WalletFragmentStyle_maskedWalletDetailsButtonTextAppearance /*7*/:
                    if (this.mAppUuid == null) {
                        addBytesInstallAndBank();
                        break;
                    }
                    addBytesUUID();
                    break;
            }
        }
        return super.getBytes();
    }
}
